package com.example.admin.controller;


import com.example.admin.common.Result;
import com.example.admin.entity.ServiceStaff;
import com.example.admin.service.ServiceStaffService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:8080")
public class ServiceStaffController {


    @Autowired
    private ServiceStaffService serviceStaffService;

    @GetMapping("/getServiceStaffPage")
    public Result<PageInfo> getServiceStaffPage(@RequestParam Integer pageNumber, @RequestParam Integer pageSize) {

        PageHelper.startPage(pageNumber, pageSize);

        List<ServiceStaff> serviceStaffList = serviceStaffService.getServiceStaffPage();
        return Result.success(new PageInfo(serviceStaffList));


    }


    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {

       Result result= serviceStaffService.deleteById(id);
       return result;
    }


    @PostMapping("/addServiceStaff")
    public Result addServiceStaff(@RequestBody ServiceStaff serviceStaff) {
      Result result=  serviceStaffService.addServiceStaff(serviceStaff);
      return result;
    }

    @PutMapping("/editeServiceStaffInfo")
    public Result editServiceStaffInfo(@RequestBody ServiceStaff serviceStaff) {
       Result result= serviceStaffService.editServiceStaffInfo(serviceStaff);
       return result;
    }

    @GetMapping("/selectByName")
    public Result<PageInfo> selectByName(@RequestParam String name) {

        PageHelper.startPage(1,10);
        List<ServiceStaff> serviceStaffList=serviceStaffService.selectByName(name);
        return Result.success(new PageInfo(serviceStaffList));
    }
}
